package com.ruitu.mall_98_2.mine;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.beanu.arad.base.my_base.MyBaseActivity;
import com.beanu.arad.widget.NoScrollViewPager;
import com.beanu.arad.widget.progressactivity.ProgressLayout;
import com.ruitu.mall_98_2.R;
import com.ruitu.mall_98_2.mine.fragment.FragmentAttention;
import com.ruitu.mall_98_2.mine.fragment.FragmentCollection;
import com.ruitu.mall_98_2.mine.fragment.FragmentFootprint;

public class UserProductActivity extends MyBaseActivity {
    private TabLayout tabLayout;
    private NoScrollViewPager viewPager;

    private ViewPagerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_user_product;
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    @Override
    protected void initViews() {
        super.initViews();
        int position = getIntent().getIntExtra("position", 0);
        if (position == 0) {
            setHeadTitle("商品收藏");
        } else if (position == 1) {
            setHeadTitle("企业关注");
        } else {
            setHeadTitle("浏览历史");
        }
        tabLayout = findViewById(R.id.tabLayout);
        viewPager = findViewById(R.id.viewPager);
        viewPager.setScanScroll(false);
        adapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setCurrentItem(position);
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {
        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return FragmentCollection.newInstance();
            } else if (position == 1) {
                return FragmentAttention.newInstance();
            } else {
                return FragmentFootprint.newInstance();
            }

        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            String titleName[] = {"收藏", "关注", "足迹"};
            return titleName[position];
        }
    }
}
